package com.atguigu.lease.web.admin.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;


/**
 * ClassName: StringToItemTypeConverter
 * Package: com.atguigu.lease.web.admin.converter
 * Description:
 *
 * @Author ygf
 * @Create 2024/9/26 17:22
 * @Version 1.0
 */
//@Component
public class StringToItemTypeConverter implements Converter<String,ItemType> {
    @Override
    public ItemType convert(String source) {
        //获取所有的枚举值（APARTMENT，ROOM）
        ItemType[] values = ItemType.values();
        //遍历得到每一个
        for (ItemType value : values) {
            //判断
            if(value.getCode().equals(Integer.parseInt(source))){
                return value;
            }
        }
        throw new IllegalArgumentException("参数不合法");
    }
}
